<?php

	header("Content-Type: text/html;charset=utf-8");

	include("../function/_nosql.php"); //
	include("../function/function.php");
	include("../_include.user.judge.php");
//  $_SESSION['kboy_userid'] = 54;
	$kboy_userid = $_SESSION['kboy_userid'];
//	$kboy_userid = 54;
//	搜索订单号
	$search_text = chkstr(trim($_REQUEST['search_text']));

	$state = chkstr(intval($_REQUEST['state']));

	function str_count($sql,$str){

 $res = mysql_query($sql);

 $num = mysql_num_rows($res);

 $count = 0;

  if($num>0){

	while($arr=mysql_fetch_array($res)){

	 $count = $count + $arr[$str];

	}

  }

  return $count;

}	

?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">
    <title>我的订单</title>
    <link rel="stylesheet" href="css/bootstrap.min.css"/>
    <link rel="stylesheet" href="css/style.css"/>
    <script type="text/javascript" src="../js/baidutongji.js"></script>
</head>
<body class="recycle send order">
<div class="main">
    <span class="nav block align"><i class="block">我的订单</i></span>
    <!--<div class="nav liebiao ">
    	<h4 style="display: inline-block;">订单列表</h4>
    	<span><input type="text" name="dingdan" id="dingdan" value="输入订单编号" />
    		<input type="button" name="button" id="button" value="搜素" />
		</span>
    </div>-->
    <?php

						$SQL = " uid = '".$_SESSION['kboy_userid']."'   ";

						if($search_text){

						 $SQL = $SQL." and `order_no` like '%".$search_text."%' ";

						}

						if($state == 1 ){//未付款订单

						 $SQL = $SQL." and `order_state` = 0  ";

						}

						if($state == 2 ){//已经付款订单

						 $SQL = $SQL." and `order_state` = 1  ";

						}

						if($state == 3 ){//已经结束订单

						 $SQL = $SQL." and `aid` in ( select * from kboy_forum_active where active_end_time <= '".date('Y-m-d H:i:s')."'  )   ";

						}



						$pagesize = 5; // 分页数量

						$pageval = chkstr(trim($_REQUEST['page'])); // 获取Page的值

						if($pageval){

							if(!is_numeric($pageval)){

								echo erro("Page Error");

							}

							if($pageval <= 1){

								$pageval = 1;

							}

							$page = ($pageval-1) * $pagesize;

							$page .= ",";

						}else{

							$pageval = 1;

						}

						

						if($SQL != ""){

							$pagesql = "select * from kboy_order  where ".$SQL." order by id desc";

						}else{

							$pagesql = "select * from kboy_order order by id desc";

						}



						$pagenum = mysql_num_rows(mysql_query($pagesql)); // 总记录数

						$pagecount = ceil($pagenum/$pagesize); // 共分多少页

						if($pageval > $pagecount){

							$pageval = $pagecount;

						}

						

						$news_sql = $pagesql." limit $page $pagesize";

						$news_rows = mysql_query($news_sql);

						$i = 1;

						while($news_rs = mysql_fetch_array($news_rows)){

						  $active_sql = "select * from kboy_forum_active where id = '".$news_rs['aid']."' ";

						  $active_res = mysql_query($active_sql);

						  $active_arr = mysql_fetch_array($active_res)

						?>
    <div class="content pull-left">
    	<p class="bianhao">订单编号：<?=$news_rs['order_no'];?></p>
        <span class="pull-left"><img src="../<?php  
                                       			 $news_rss = explode(',',$active_arr['active_pic']);
												if($news_rss){
													echo $news_rss[0];
												}else{
													echo $active_arr['active_pic'];
												}
                                        ?>" alt=""/></span>
            <span class="pull-left text_hid">
                <i class="block"><?=$active_arr['active_title'];?></i>
                <i class="block"><span><?=str_count("select * from  kboy_order where order_tuiactive_content = '' and order_tui_content = '' and aid=".$news_rs['aid']."  group by uid","order_num");?></span>人已参与</i>
                <i class="block state"><?=$news_rs['order_addtime'];?></i>
                <i class="block state">￥<?php if(getClassName("kboy_user","user_style","uid=".$kboy_userid) == 1){ 
                									if($news_rs['order_isfull']==1){ 
                										echo $qian = ($active_arr['active_cva_money']*$news_rs['order_num']) ;
                									}else{ 
                										echo $qian = ($active_arr['active_part_money']*$news_rs['order_num'])  ;
                									}  
                								}else{ if($news_rs['order_isfull']==1){ 
                										echo $qian = ($active_arr['active_all_money']*$news_rs['order_num'])  ;
                									}else{ 
                										echo $qian = ($active_arr['active_part_money']*$news_rs['order_num'])  ;
                									}  
                								}  ?>元</i>
            </span>
            <span class="pull-left but" >
            	<?php

								 if($news_rs['order_state'] == 1 && $news_rs['order_states'] == 0 ){

								 echo "<a href=\"javascript:void(0)\" class=\"operate operate-over\">已付款</a>";

								  if(getNewsNums("kboy_active_score","uid=".$_SESSION['kboy_userid']." and orderid=".$news_rs['id']) <1 &&  date('Y-m-d H:i:s') <= $active_arr['active_start_time'] ){

									echo "<a href=\"../user_tuimoney.php?orderid=".$news_rs['id']."\" class=\"operate operate-pay\">退款</a>";

								    }

								 }
 
								 if( date('Y-m-d H:i:s') <= $active_arr['active_start_time'] && $news_rs['order_states'] == 0   ){

								 echo "<a href=\"../user_tuiactive.php?orderid=".$news_rs['id']."\" class=\"operate operate-pay\">退出活动</a>";

								 }

								 if( $news_rs['order_states'] == 4 ){

								  echo "<a href=\"javascript:void(0)\" class=\"operate operate-over\">退出活动中</a>";

								 }

								 if( $news_rs['order_states'] == 5 ){

								  	echo "<a href=\"javascript:void(0)\" class=\"operate operate-over\">退出活动成功</a>";
								// 	echo "<a href=\"../user_orderaddsave.php?action=del&id=".$news_rs['order_no']."\" class=\"operate operate-pay\">删除订单</a>";
									echo "<a onclick=\"if(confirm('确定删除吗？')){location.href='../user_orderaddsave.php?action=del&id=".$news_rs['order_no']."'}\" class=\"operate operate-pay\">删除订单</a>";
								 }

								  if( $news_rs['order_states'] == 6 ){

								  echo "<a href=\"javascript:void(0)\" class=\"operate operate-over\">退出活动失败</a>";

								 }

								  if($news_rs['order_state'] == 1 && $news_rs['order_states'] == 1 ){

								  echo "<a href=\"javascript:void(0)\" class=\"operate operate-over\">退款中</a>";

								 }

								  if($news_rs['order_state'] == 1 && $news_rs['order_states'] == 2 ){

								  echo "<a href=\"javascript:void(0)\" class=\"operate operate-over\">退款成功</a>";

								 }

								  if($news_rs['order_state'] == 1 && $news_rs['order_states'] == 3 ){

								  echo "<a href=\"javascript:void(0)\" class=\"operate operate-over\">退款失败</a>";

								 }

								  if($news_rs['order_state'] == 0 && $active_arr['active_all_money'] != 0  && $news_rs['order_states'] == 0  ){
                                        
							       // echo "<a href=\"../weipay/jsapi.php?WIDout_trade_no=".$news_rs['order_no']."&aid=".$news_rs['aid']."\" class=\"operate operate-pay\">立即付款</a>";
							    
								 	echo "<a href=\"yu_e_zhifu.php?WIDout_trade_no=".$news_rs['order_no']."&aid=".$news_rs['aid']."\" class=\"operate operate-pay\">立即支付</a>";
								
								//   echo "<a href=\"../user_orderaddsave.php?action=del&id=".$news_rs['order_no']."\" class=\"operate operate-pay\">删除订单</a>";
								   echo "<a onclick=\"if(confirm('确定删除吗？')){location.href='../user_orderaddsave.php?action=del&id=".$news_rs['order_no']."'}\" class=\"operate operate-pay\">删除订单</a>";

								 }

								  if( date('Y-m-d H:i:s') > $active_arr['active_end_time']){

								   echo "<a href=\"javascript:void(0)\" class=\"operate operate-over\">活动结束</a>";

								    if(getNewsNums("kboy_active_score","uid=".$_SESSION['kboy_userid']." and orderid=".$news_rs['id']) <1 ){

								    echo "<a href=\"../user_ping.php?orderid=".$news_rs['id']."\" class=\"operate operate-pay\">评价</a>";

								    }

								 }

								  if($active_arr['active_all_money'] == 0){

								   if(date('Y-m-d H:i:s') >=  $active_arr['active_start_time'] && date('Y-m-d H:i:s') <= $active_arr['active_end_time']){

								   echo "<a href=\"javascript:void(0)\" class=\"operate operate-over\">活动进行中</a>";

								   }

								   if(date('Y-m-d H:i:s') <=  $active_arr['active_start_time'] ){

								   echo "<a href=\"javascript:void(0)\" class=\"operate operate-over\">活动未开始</a>";

								   }

								 }

								?> 
            </span>
    </div>
    <?php

		}

	?>
									<?php

										echo "<div class=\"pagination\"><ul>";

										$url = "order.php?search_text=$search_text";//当前页面

										pagebar($pagecount, $pageval, 2, $url);

										echo "</ul></div>";

						           ?>
</div>
<footer>
    <nav class="navbar navbar-default navbar-fixed-bottom">
        <div class="col-xs-12 btn-group">
            <a href="index.php" class="col-xs-3 nopadding text-center bottomDiv">
                <span class="dora-font">首页</span>
            </a>

            <a href="huodong.php" class="col-xs-3 nopadding text-center bottomDiv">
                <span class="dora-font">活动</span>
            </a>

            <a href="mycloset.php" class="col-xs-3 nopadding text-center bottomDiv">
                <span class="dora-font">社区</span>
            </a>

            <a href="personal.php" class="col-xs-3 nopadding text-center bottomDiv">
                <span class="dora-font">我</span>
            </a>
        </div>
    </nav>
</footer>
</body>
<script type="application/javascript" src="js/jquery.min.js"></script>
<script type="application/javascript" src="js/bootstrap.min.js"></script>
<script type="application/javascript">
    $(function () {
        $(".choose").click(function(){
            if($(this).hasClass("selected")){
                $(this).html("&#xe62c;");
                $(this).removeClass("selected");
            }else{
                $(this).html("&#xe629;");
                $(this).addClass("selected");
            }
        });
    });
</script>
</html>